/**
 * @description useFetch请求封装
 */
export const useFetchData = async ({ url, method = "get", params }) => {
  const headers = useRequestHeaders(["cookie"]);
  const query = method === "get" ? { params } : { body: params };
  const { data } = await useFetch(url, {
    headers,
    method,
    ...query,
  });
  return new Promise((resolve, reject) => {
    if (data.value.code == 200) {
      resolve(data.value.data);
    } else {
      reject(data.value.message || "接口服务异常");
    }
  });
};

export const $fetchData = async ({ url, method, params }) => {
  const query = method === "get" ? { params } : { body: params };
  const data = await $fetch(url, {
    method,
    ...query,
  });
  return new Promise((resolve, reject) => {
    if (data.code == 200) {
      resolve(data.data);
    } else {
      reject(data.data.message || "接口服务异常");
    }
  });
};
